/*
 * File: FltLevelSettingCF.c
 *
 * Code generated for Simulink model 'FLTM'.
 *
 * Model version                  : 3.512
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Tue Apr 26 13:54:46 2022
 */

#include "FltLevelSettingCF.h"

/* Named constants for Chart: '<S46>/FetLevelSetCF' */
#define IN_Err_LV1                     ((uint8_T)1U)
#define IN_Err_LV2                     ((uint8_T)2U)
#define IN_Err_LV3                     ((uint8_T)3U)
#define IN_Err_LV4                     ((uint8_T)4U)
#define IN_Err_Nor                     ((uint8_T)5U)
#define IN_FltJudge                    ((uint8_T)1U)
#define IN_Init                        ((uint8_T)2U)
#define IN_NO_ACTIVE_CHILD             ((uint8_T)0U)

/*
 * Output and update for atomic system:
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    'FetLevelSetCF' ('mylib:203')
 *    ...
 */
void FltLevelSettingCF(boolean_T LV1Cfm, boolean_T LV1Cel, boolean_T LV2Cfm,
                       boolean_T LV2Cel, boolean_T LV3Cfm, boolean_T LV3Cel,
                       boolean_T LV4Cfm, boolean_T LV4Cel, B_FltLevelSettingCF_T
                       *localB, DW_FltLevelSettingCF_T *localDW, uint8_T
                       rtp_Flttye, boolean_T *rtd_ClearFault)
{
    boolean_T tmp;
    boolean_T tmp_0;
    boolean_T tmp_1;
    if (localDW->is_active_c2_mylib == 0U)
    {
        localDW->is_active_c2_mylib = 1U;
        localDW->is_c2_mylib = IN_Init;
        localB->ScFlt_LV = 0U;
    }
    else if (localDW->is_c2_mylib == IN_FltJudge)
    {
        if (*rtd_ClearFault)
        {
            localDW->is_FltJudge = IN_NO_ACTIVE_CHILD;
            localDW->is_c2_mylib = IN_Init;
            localB->ScFlt_LV = 0U;
        }
        else
        {
            switch (localDW->is_FltJudge)
            {
              case IN_Err_LV1:
                localB->ScFlt_LV = 1U;
                if (LV4Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV4;
                    localB->ScFlt_LV = 4U;
                }
                else if (LV3Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV3;
                    localB->ScFlt_LV = 3U;
                }
                else if (LV2Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV2;
                    localB->ScFlt_LV = 2U;
                }
                else
                {
                    if (LV1Cel)
                    {
                        localDW->is_FltJudge = IN_Err_Nor;
                        localB->ScFlt_LV = 0U;
                    }
                }
                break;

              case IN_Err_LV2:
                localB->ScFlt_LV = 2U;
                if (LV4Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV4;
                    localB->ScFlt_LV = 4U;
                }
                else if (LV3Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV3;
                    localB->ScFlt_LV = 3U;
                }
                else if (LV2Cel && (!LV1Cfm))
                {
                    localDW->is_FltJudge = IN_Err_Nor;
                    localB->ScFlt_LV = 0U;
                }
                else
                {
                    if (LV2Cel)
                    {
                        localDW->is_FltJudge = IN_Err_LV1;
                        localB->ScFlt_LV = 1U;
                    }
                }
                break;

              case IN_Err_LV3:
                localB->ScFlt_LV = 3U;
                if (LV4Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV4;
                    localB->ScFlt_LV = 4U;
                }
                else
                {
                    tmp_0 = !LV2Cfm;
                    if (LV3Cel && (!LV1Cfm) && tmp_0)
                    {
                        localDW->is_FltJudge = IN_Err_Nor;
                        localB->ScFlt_LV = 0U;
                    }
                    else if (LV3Cel && LV1Cfm && tmp_0)
                    {
                        localDW->is_FltJudge = IN_Err_LV1;
                        localB->ScFlt_LV = 1U;
                    }
                    else
                    {
                        if (LV3Cel)
                        {
                            localDW->is_FltJudge = IN_Err_LV2;
                            localB->ScFlt_LV = 2U;
                        }
                    }
                }
                break;

              case IN_Err_LV4:
                localB->ScFlt_LV = 4U;
                tmp_0 = !LV2Cfm;
                tmp = !LV3Cfm;
                tmp_1 = (LV4Cel && (!LV1Cfm));
                if (tmp_1 && tmp_0 && tmp)
                {
                    localDW->is_FltJudge = IN_Err_Nor;
                    localB->ScFlt_LV = 0U;
                }
                else if (LV4Cel && LV1Cfm && tmp_0 && tmp)
                {
                    localDW->is_FltJudge = IN_Err_LV1;
                    localB->ScFlt_LV = 1U;
                }
                else if (tmp_1 && LV2Cfm && tmp)
                {
                    localDW->is_FltJudge = IN_Err_LV2;
                    localB->ScFlt_LV = 2U;
                }
                else
                {
                    if (LV4Cel)
                    {
                        localDW->is_FltJudge = IN_Err_LV3;
                        localB->ScFlt_LV = 3U;
                    }
                }
                break;

              default:
                /* case IN_Err_Nor: */
                localB->ScFlt_LV = 0U;
                if (LV4Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV4;
                    localB->ScFlt_LV = 4U;
                }
                else if (LV3Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV3;
                    localB->ScFlt_LV = 3U;
                }
                else if (LV2Cfm)
                {
                    localDW->is_FltJudge = IN_Err_LV2;
                    localB->ScFlt_LV = 2U;
                }
                else
                {
                    if (LV1Cfm)
                    {
                        localDW->is_FltJudge = IN_Err_LV1;
                        localB->ScFlt_LV = 1U;
                    }
                }
                break;
            }
        }
    }
    else
    {
        /* case IN_Init: */
        localB->ScFlt_LV = 0U;
        if ((rtp_Flttye == 1) && (!*rtd_ClearFault))
        {
            localDW->is_c2_mylib = IN_FltJudge;
            localDW->is_FltJudge = IN_Err_Nor;
            localB->ScFlt_LV = 0U;
        }
    }
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
